/**
 * 给定字符串，删除最少的字符使得所有单词
 * 1. 首字母大写其余全小写
 * 2. 全小写
 * 贪心即可
 */
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;

template <typename T>
const T & mymax(const T & a, const T & b){
    return max(a, b);
}

template<typename T, typename ... Args>
const T & mymax(const T & t, const Args & ... args){
    return max(t, mymax(args ...));
}

template<typename T>
void input(vector<T> & v, int n){
	v.assign(n + 1, {});
    for(int i=1;i<=n;++i) cin >> v[i];
	return;
}

template<typename T>
istream & operator >> (istream & is, vector<T> & v){
	for(auto & i : v) is >> i;
	return is;
}

using llt = long long;
using vi = vector<int>;
using vll = vector<llt>;
using pii = pair<int, int>;
using vpii =vector<pii>;

llt const INF = 0x3F4F5F6F7F8F9FAF;

string S;

int proc(){
    int n = S.length();
    
    int ans = 0;
    int pre = 0;
    for(int i=0;i<n;++i){
        if(isupper(S[i])){
            if(1 == pre){
                pre = 0;
                ans += 1;
            }else{
                pre = 1;
            }
        }else{
            pre = 1;
        }
    }
    return ans;
}


int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0);   
    cin >> S;
    cout << proc() << endl;
    return 0;
}